package com.lifo.utils.quartz;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.quartz.CronTriggerFactoryBean;
import org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;

/**
 * Created by Administrator on 2018/5/10.
 */
@Configuration
public class MatchGoodCategoryConfig {


    @Bean(name="detailFactoryBean")
    public MethodInvokingJobDetailFactoryBean detailFactoryBean(MatchGoodCategoryJob matchGoodCategoryJob){
        MethodInvokingJobDetailFactoryBean bean = new MethodInvokingJobDetailFactoryBean();
        bean.setTargetObject(matchGoodCategoryJob);
        bean.setTargetMethod("mathcGood");
        bean.setConcurrent(false);
        return  bean;
    }

    @Bean(name = "cronTriggerBean")
    public CronTriggerFactoryBean cronTriggerBean(MethodInvokingJobDetailFactoryBean detailFactoryBean){
        CronTriggerFactoryBean trigger = new CronTriggerFactoryBean ();
        trigger.setJobDetail (detailFactoryBean.getObject ());
        try {
            trigger.setCronExpression ("0 0/5 * * * ?");
            //小时执行一次
        } catch (Exception e) {
            e.printStackTrace ();
        }
        return trigger;

    }

    @Bean
    public SchedulerFactoryBean schedulerFactory(CronTriggerFactoryBean cronTriggerBean){
        SchedulerFactoryBean schedulerFactory = new SchedulerFactoryBean ();
        schedulerFactory.setTriggers(cronTriggerBean.getObject());
        return schedulerFactory;
    }


}
